#include "suppliersdialog.h"
#include "ui_suppliersdialog.h"

suppliersDialog::suppliersDialog(QStandardItemModel *mainModel, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::suppliersDialog)
{
    model = mainModel;
    model->setColumnCount(5);

    ui->setupUi(this);
    ui->tableView->setModel(model);
}

suppliersDialog::~suppliersDialog()
{
    delete ui;
}

void suppliersDialog::on_AddSupplier_clicked()
{
    int row = model->rowCount();
    model ->insertRow(row);

    QModelIndex index = model ->index(row,0);
    model ->setData(index,QVariant("Nowy poddostawca"));

    index = model ->index(row,1);
    model ->setData(index,QVariant("produkt"));

    index = model ->index(row,2);
    model ->setData(index,QVariant(2));

    index = model ->index(row,3);
    model ->setData(index,QVariant(3));

    index = model ->index(row,4);
    model ->setData(index,QVariant(4));

    ui -> tableView ->setCurrentIndex(index);
    ui -> tableView ->edit(index);
}

void suppliersDialog::on_InsertSupplier_clicked()
{
   int row = ui->tableView->currentIndex().row();
   model ->insertRow(row);

   QModelIndex index = model ->index(row,0);
   model ->setData(index,QVariant("Nowy poddostawca"));

   index = model ->index(row,1);
   model ->setData(index,QVariant("produkt"));

   index = model ->index(row,2);
   model ->setData(index,QVariant(2));

   index = model ->index(row,3);
   model ->setData(index,QVariant(3));

   index = model ->index(row,4);
   model ->setData(index,QVariant(4));

   ui -> tableView ->setCurrentIndex(index);
   ui -> tableView ->edit(index);
}

void suppliersDialog::on_RemoveSupplier_clicked()
{
    int row = ui->tableView->currentIndex().row();
    model ->removeRow(row);
}

void suppliersDialog::on_closeSupplier_clicked()
{
    this->close();
}

void suppliersDialog::on_SaveSupplier_clicked()
{

}

void suppliersDialog::on_CancelSupplier_clicked()
{
    this->close();
}
